package parser

import (
	"imooc.com/crawler/engine"
	"regexp"
	"imooc.com/crawler_distrilbuted/config"
)

const cityListReg  = `<a[^<]*href="(http://www.zhenai.com/zhenghun/[a-z0-9]+)"[^>]*>([^<]+)</a>`

func ParseCityList(contents []byte, _ string) engine.ParseResult  {
	reg := regexp.MustCompile(cityListReg)

	all := reg.FindAllStringSubmatch(string(contents), -1)

	var parseResult engine.ParseResult
	for _,m := range all {
		//parseResult.Items = append(parseResult.Items, "City " + string(m[2]))
		parseResult.Request = append(parseResult.Request, engine.Request{
			Url:m[1],
			Parser: engine.NewFuncParser(ParseCity, config.ParseCity),
		})
	}

	return parseResult
}